<?php

declare(strict_types=1);
/**
 * This file is part of bearing-web.
 *
 * @link     https://www.bearing.cn/
 * @contact  tech@bearing.cn
 * @license  https://gitee.com/cppo/bearing_web/-/blob/master/README.md
 */

namespace frontend\controllers;

use yii\base\DynamicModel;
use yii\helpers\ArrayHelper;
use yii\web\ForbiddenHttpException;

class OrdersController extends BaseController
{
    public $modelClass = 'common\models\OrderModel';

    public function actions(): array
    {
        return ArrayHelper::merge(
            parent::actions(),
            [
                'index' => [
                    'class' => 'frontend\actions\OrderIndexAction',
                    'dataFilter' => [
                        'class' => 'yii\data\ActiveDataFilter',
                        'searchModel' => function () {
                            return (new DynamicModel([
                                'user_id' => 0,
                            ]))->addRule('user_id', 'integer');
                        },
                    ],
                ],
                'view' => [
                    'class' => 'frontend\actions\OrderViewAction',
                ],
            ]
        );
    }

    public function checkAccess($action, $model = null, $params = []): void
    {
        if (\Yii::$app->user->isGuest) {
            throw new ForbiddenHttpException(\Yii::t('yii', 'You are not allowed to perform this action.'));
        }
        parent::checkAccess($action, $model, $params); // TODO: Change the autogenerated stub
    }
}
